package com.netease.nie.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.netease.nie.base.utils.CopyUtils;
import com.netease.nie.constants.LogisticsCompanyConstants;
import com.netease.nie.dao.LogisticsDao;
import com.netease.nie.dto.LogisticsDto;
import com.netease.nie.model.Logistics;

@Service
public class LogisticsServiceImpl implements LogisticsService {

	@Autowired
	private LogisticsDao logisticsDao;

	public LogisticsDto queryLogisticsByOrdersId(long orderId){		
		Logistics logistics = logisticsDao.queryLogisticsByOrdersId(orderId);
		if (logistics == null)
			return null;
		
		LogisticsDto logisticsDto = new LogisticsDto();
		CopyUtils.copy(logisticsDto, logistics);
		Map<String, String> logisticsCompanyMap = mapLogisticsCompany();
		//将物流公司编号转化为名称
		logisticsDto.setLogisticsCompanyTitle(logisticsCompanyMap.get(logistics.getLogisticsCompany()));
		return logisticsDto;
	}
	
	private Map<String, String> mapLogisticsCompany() {
		Map<String, String> logisticsCompanyMap = new HashMap<>();
		for (LogisticsCompanyConstants logisticsCompanys : LogisticsCompanyConstants.values()) {
			logisticsCompanyMap.put(logisticsCompanys.getCode(), logisticsCompanys.getMsg());
		}
		return logisticsCompanyMap;
	}
}
